package io.renren.auth.factory;


import feign.hystrix.FallbackFactory;
import io.renren.auth.remote.RemoteUserService;
import io.renren.common.form.SysLoginForm;
import io.renren.common.utils.R;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.Map;

/**
 * 用户服务降级处理
 * 
 * @author ruoyi
 */
@Component
public class RemoteUserFallbackFactory implements FallbackFactory<RemoteUserService>
{
    private static final Logger log = LoggerFactory.getLogger(RemoteUserFallbackFactory.class);

    @Override
    public RemoteUserService create(Throwable throwable)
    {
        log.error("用户服务调用失败:{}", throwable.getMessage());
        return new RemoteUserService()
        {
            @Override
            public Map<String, Object> login(@RequestBody SysLoginForm form)
            {
                return R.error("获取用户失败:" + throwable.getMessage());
            }


        };
    }
}
